package cn.java79.springboot.pojo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
//分页专用
public class AjaxPage<T> implements Serializable {
    //本页中的数据
    private List<T> data=new ArrayList<>(0);
    //总数
    private long count=0;
    //当前页
    private int page=1;
    //页大小
    private int pageSize=10;
    //总页数
    private int pageNums=0;

    public AjaxPage(){

    }
    public AjaxPage(List<T> data, long count,int pageSize) {
        this.data = data;
        this.count = count;
        this.pageSize = pageSize;
    }
    public AjaxPage(List<T> data, long count, int page, int pageSize) {
        this.data = data;
        this.count = count;
        this.page = page;
        this.pageSize = pageSize;
    }
    public AjaxPage(List<T> data, long count, int page, int pageSize, int pageNums) {
        this.data = data;
        this.count = count;
        this.page = page;
        this.pageSize = pageSize;
        this.pageNums = pageNums;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public long getCount() {
        return count;
    }
    //最好在setPage之后
    public void setCount(long count) {
        this.count = count;
        this.pageNums= (int) (count/pageSize+(count%pageSize==0?0:1));
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNums() {
        return pageNums;
    }

    public void setPageNums(int pageNums) {
        this.pageNums = pageNums;
    }

    @Override
    public String toString() {
        return "AjaxPage{" +
                "data=" + data +
                ", count=" + count +
                ", page=" + page +
                ", pageSize=" + pageSize +
                ", pageNums=" + pageNums +
                '}';
    }
}
